<?php
	//create by mamat, July 14, 2007
	//edited by mamat,
	//this class for handle guestbook
	
	class Guestbook {
		//for add to guesbook
		function addGuestbook($name, $email, $website, $message) {
			if($this->cekEmail($email)) {
				$mysql = new Mysql();
				$mysql->connect();
				if($mysql->execute("insert into guestbook (name, email, website, message) values ('".htmlentities($name)."','".$email."','".htmlentities($website)."','".htmlentities($message)."')")){
					return true;
				} else {
					return false;
				}
				$mysql->closeConnection();
				
			} else {
				return false;
			}
		}
		
		//function for delete
		function deleteGuestbook($guestbookId) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("delete from guestbook where guestbookId = ".$guestbookId."")) {
				return true;
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//function for get data
		function getGuestbook($guestbookId) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("select * from guestbook where guestbookId = ".$guestbookId."")) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//function for get data for detail with query
		function getDetailGuestbook($query="select * from guestbook order by guestbookId desc limit 0,1") {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//function for cek email
		private function cekEmail($email){
			if (!eregi( "^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $email)) {
				return false;
			} else {
				return true;
			}
		}
	
	}
?>